package q1.project.modules.system.user.entity;

import jakarta.persistence.*;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
import q1.project.common.enums.GenderEnum;
import q1.project.core.entity.BaseEntity;
import q1.project.core.jpa.annotation.Comment;
import q1.project.modules.system.user.enums.UserStatusEnum;

/**
 * 用户实体
 *
 * @author Q1 Team
 * @version 1.0
 */
@Getter
@Setter
@Entity
@Table(
    name = "q1_user",
    indexes = {
      @Index(name = "idx_username", columnList = "username"),
      @Index(name = "idx_email", columnList = "email"),
      @Index(name = "idx_phone", columnList = "phone"),
      @Index(name = "idx_status", columnList = "status")
    })
public class UserEntity extends BaseEntity {

  /** 用户名 */
  @Comment("用户名")
  @Column(nullable = false, length = 50)
  private String username;

  /** 密码（SM3加密） */
  @Comment("密码")
  @Column(nullable = false)
  private String password;

  /** 邮箱 */
  @Comment("邮箱")
  @Column(length = 100)
  private String email;

  /** 手机号 */
  @Comment("手机号")
  @Column(length = 20)
  private String phone;

  /** 昵称 */
  @Comment("昵称")
  @Column(length = 50)
  private String nickname;

  /** 头像（Base64编码） */
  @Comment("头像")
  @Column(columnDefinition = "TEXT")
  private String avatar;

  /** 个性签名 */
  @Comment("个性签名")
  @Column(length = 200)
  private String signature;

  /** 性别：MALE-男, FEMALE-女, UNKNOWN-未知 */
  @Comment("性别")
  @Enumerated(EnumType.STRING)
  @Column(length = 10)
  private GenderEnum gender = GenderEnum.UNKNOWN;

  /** 生日 */
  @Comment("生日")
  @Column
  private java.time.LocalDate birthday;

  /** 所在地 */
  @Comment("所在地")
  @Column(length = 100)
  private String location;

  /** 状态：ACTIVE-激活, LOCKED-锁定, DISABLED-禁用 */
  @Comment("状态")
  @Enumerated(EnumType.STRING)
  @Column(nullable = false, length = 20)
  private UserStatusEnum status = UserStatusEnum.ACTIVE;

  /** 是否管理员 */
  @Comment("是否管理员")
  @Column(name = "is_admin", nullable = false)
  private Boolean isAdmin = false;

  /** 最后登录时间 */
  @Comment("最后登录时间")
  @Column(name = "last_login_time")
  private LocalDateTime lastLoginTime;

  /** 最后登录IP */
  @Comment("最后登录IP")
  @Column(name = "last_login_ip", length = 50)
  private String lastLoginIp;

  /** 备注 */
  @Comment("备注")
  @Column(columnDefinition = "text")
  private String remark;

  // 注意：用户角色关联使用QueryDSL进行连表查询，不使用JPA注解
}
